<template>
    <div class="app-container">
        <header-title/>
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="关键词" prop="keyword">
                <el-input
                    v-model="queryParams.keyword"
                    placeholder="请输入名字/编号"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="日期">
                <el-date-picker
                style="width: 217px"
                v-model="dateRange"
                size="small"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>

            
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="dataList">
            <!-- ，今日充值，累计消耗算力，数字人消耗，混剪消耗，.....各个单项消耗 -->
            <el-table-column label="日期" align="center" prop="day" width="100"/>
            <el-table-column label="今日充值" align="center" width="100">
                <template slot-scope="scope">
                    {{ scope.row.todayRecharge}}元
                </template>
            </el-table-column>
            <el-table-column label="今日消耗算力" align="center" prop="todayConsumePoint" width="100"/>
            
            <el-table-column 
                v-for="(item, index) in ((tableList.length > 0 && tableList[0].reportYewuDailyTodayAiCousumes) ? tableList[0].reportYewuDailyTodayAiCousumes : [])" 
                :key="index"
                :label="selectDictLabel(dict.type.ai_type, item.aiType)" 
                align="center"
                min-width="100"
            >
                <template slot-scope="scope">
                    {{ scope.row[item.aiType] || 0 }}
                    <!-- {{scope.row.reportYewuDailyTodayAiCousumes[]}} -->
                    <!-- {{ item.consumePoint || 0}} -->
                </template>
            </el-table-column>
        
            
        </el-table>

        <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
        />
    </div>
</template>
<script>
    import {getReportYewuDaily} from '@/api/index'
    export default{
        name:'Order',
        dicts:['ai_type'],
        data() {
            return {
                showSearch:true,
                queryParams: {
                    pageSize: 10,
                    pageNum:1,
                    keyword:"",
                    startDay:'',
                    endDay:'',
                },
                loading: true,
                total: 0,
                // 表格数据
                tableList: [],
                dateRange: [],

            }
        },
        created() {
            this.getList()
        },
        computed: {
            dataList() {
                return this.tableList.map(item => {
                    let consumeMap = {};
                    item.reportYewuDailyTodayAiCousumes.forEach(ai => {
                        consumeMap[ai.aiType] = ai.consumePoint;
                    });  
                    return {
                        ...item,
                        ...consumeMap // 直接展开，成为行内字段
                    };
                })
                
            }
        },
        methods: {
            getList() {
                this.loading = true;
                if(this.dateRange && this.dateRange.length){
                    this.queryParams.startDay = this.dateRange[0]
                    this.queryParams.endDay = this.dateRange[1]
                }else{
                    this.queryParams.startDay = undefined
                    this.queryParams.endDay = undefined
                }
                getReportYewuDaily(this.queryParams).then(response => {
                    this.tableList = response.data.records;
                    this.total = response.data.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
                console.log(this.dataList,'data')
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = []
                this.resetForm("queryForm");
                this.handleQuery();
            },
        }
    }
</script>